<script setup lang="ts">
import {archivesApi} from "@/api/blog/archivesApi.ts";
import {onMounted, ref} from "vue";
import day from "@/utils/dateUtils.ts";
const archives = ref( [
  {
    year: "2025",
    total: 1,
    archives: [
      {
        id: 1,
        title: "人工智能的未来发展",
        content: "本文探讨了人工智能技术的最新进展和未来发展趋势，包括机器学习、自然语言处理和计算机视觉等领域的突破性创新。",
        type: 1,
        coverUrl: "https://example.com/ai-future-cover.jpg",
        publishDate: "2025-04-28",
        status: 1
      }
    ]
  }]
)
onMounted(() => {
  archivesApi.getArchivesList().then(res => {
    archives.value = res.data
  })
})
</script>

<template>
  <div class="archives">
    <img class="archives-head" src="@/assets/archives-head.svg" alt="归档头">
    <div class="year-group-container">
      <div v-for="yearGroup in archives" :key="yearGroup.year" class="year-group">
        <h2>{{ yearGroup.year }}</h2>
        <div class="archive-list">
          <!--这里用于分割左右的分割线-->
          <div class="divider"></div>
          <div v-for="(archive, index) in yearGroup.archives" :key="index" class="archive-item">
            <!-- 因为index是从零开始的，所以 首个元素是偶数 -->
            <div v-if="index%2==0" class="archive-item-container-left">
              <div class="archive-cover">
                <img v-lazy="archive.coverUrl" alt="封面图">
              </div>
              <div class="archive-content">
                <h3>{{ archive.title }}</h3>
                <p>{{ archive.content }}</p>
                <span>{{ day(archive.publishDate).format('M月DD日') }}</span>
              </div>
            </div>
            <div v-else class="archive-item-container-right">
              <div class="archive-content">
                <h3>{{ archive.title }}</h3>
                <p>{{ archive.content }}</p>
                <span>{{ day(archive.publishDate).format('M月DD日') }}</span>
              </div>
              <div class="archive-cover">
                <img v-lazy="archive.coverUrl" alt="封面图">
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <img class="archives-footer" src="@/assets/archives-footer.svg" alt="归档页脚">
  </div>
</template>

<style scoped lang="less">
.archives {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 48px 100px;
  box-sizing: border-box;
  background-color: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
}
.archives-head {
  width: 26px;
  height: 22px;
}
.archives-footer {
  width: 100%;
  height: 20px;
}
.year-group-container {
  width: 100%;
  .year-group {
    h2 {
      text-align: center;
      color: #eb5c88;
      font-family: "Noto Sans SC",serif;
      letter-spacing: 0.03em; /* 增加现代感 */
      font-weight: 700;
      font-size: 40px;
      line-height: 58px;
      margin-top: 20px;
      margin-bottom: 20px;
    }
    .archive-list {
      display: flex;
      flex-direction: column;
      position: relative;
      .divider {
        position: absolute;
        left: 50%;
        top: 0;
        width: 2px;
        height: 100%;
        background-color: #dddddd;
      }
      .archive-item {
        .archive-item-container-left, .archive-item-container-right {
          display: flex;
          gap: 70px;
          margin-top: 40px;
          margin-bottom: 60px;
          .archive-cover {
            flex: 1;
            //min-width: 506px;
            width: 506px;
            height: 264px;
            //overflow: hidden;
            //border-radius: 16px;
            //border: 1px solid #e0e0e0;
            //box-sizing: border-box;
            position: relative;
            img {
              width: 100%;
              height: 100%;
              border-radius: 16px;
              border: 1px solid #e0e0e0;
              box-sizing: border-box;
              object-fit: cover;
            }
          }
          .archive-content {
            flex: 1;
            //min-width: 506px;
            width: 506px;
            height: 264px;
            overflow: hidden;
            h3 {
              margin: 0 0 8px;
              font-size: 24px;
              font-weight: 700;
              font-family: "Noto Sans SC",serif;
              line-height: 35px;
              color: #333;
            }
            p {
              margin: 4px 0;
              color: #666;
              font-size: 14px;
              font-family: "Noto Sans SC",serif;
              font-weight: 400;
              line-height: 20px;
            }
            span {
              display: block;
              margin-bottom: 8px;
              color: #eb5c88;
              font-family: "Noto Sans SC",serif;
              font-weight: 500;
              font-size: 18px;
              line-height: 26px;
            }
          }
        }
        .archive-item-container-left  {
          .archive-cover {
            &::before {
              content: "";
              position: absolute;
              top: 50%;
              left: 100%;
              transform: translateY(-50%);
              height: 1px;
              width: 35px;
              background-color: #dddddd;
            }
            &::after {
              content: "◉";
              color: #EB5C88;
              position: absolute;
              top: 50%;
              left: 100%;
              transform: translate(-50%, -50%);
              margin-left: 35px;
            }
          }
        }
        .archive-item-container-right {
          .archive-cover {
            &::before {
              content: "";
              position: absolute;
              top: 50%;
              left: 0;
              transform: translate(-100%,-50%);
              height: 1px;
              width: 35px;
              background-color: #dddddd;
            }
            &::after {
              content: "◉";
              color: #EB5C88;
              position: absolute;
              top: 50%;
              left: -35px;
              transform: translate(-50%, -50%);
            }
          }
          .archive-content {
            text-align: right;
          }
        }
      }
    }
  }
}
</style>
